package com.gate.ws.spring.process.upmsg;


import com.gate.ws.spring.request.RpcConfig;
import com.gate.ws.spring.service.MqSender;
import com.nami.basic.enums.protocol.UpCMDEnum;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述：
 *
 * @Author: lbc
 * @Date: 2023-07-16 16:31
 * @email: 594599620@qq.com
 * @Description: keep coding
 */
@Slf4j
public class PackageProcessFactory {

    private static final Map<Integer, PacketProcessor> map = new HashMap<Integer, PacketProcessor>(256);

    private RpcConfig rpcConfig;

    private MqSender mqSender;

    public PackageProcessFactory(MqSender mqSender, RpcConfig rpcConfig) {
        this.mqSender = mqSender;
        this.rpcConfig = rpcConfig;
    }

    public void init() {
        map.put(UpCMDEnum.LOGIN.getCode(), new LoginProcess(mqSender, rpcConfig));
        map.put(UpCMDEnum.PING.getCode(), new PingProcess());

        map.put(UpCMDEnum.C2C.getCode(), new C2CProcess(mqSender, rpcConfig));
        map.put(UpCMDEnum.C2G.getCode(), new C2GProcess(mqSender, rpcConfig));

        map.put(UpCMDEnum.LOGOUT.getCode(), new LogoutProcess(mqSender, rpcConfig));
        map.put(UpCMDEnum.QOS.getCode(), new QosProcess(mqSender, rpcConfig));

//        map.put(PacketEnum.LOGINOUT.getCmd(), new LogoutProcess(producer, dubboProperty));
        log.info("[UpMsgProcessorFactory] init process...");
    }

    public PacketProcessor getMessageProcess(Integer code) {
        return map.get(code);
    }


}
